import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { LoginService } from 'src/app/login/login.service';
import { MessageGetDto } from './dto/messages.get.dto';

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/json'
  })
};

@Injectable({
  providedIn: 'root'
})
export class MessagesService {
  constructor(private http: HttpClient, private loginService: LoginService) {
    httpOptions.headers = httpOptions.headers.set(
      'Authorization',
      `Bearer ${this.loginService.getToken()}`
    );
  }

  getMessages() {
    return this.http.get<MessageGetDto[]>('/api/message', httpOptions);
  }
}
